#include "stdafx.h"
#include "cz_msc.h"

/* ExpandStringX--------------------------------------------------------------------------------------------*/
wstring cz_msc_ExpandStringW(wstringc& wcs)
{
	u32 size;
	wstring wcsTemp;
	wchar* pwcs;

	size = ExpandEnvironmentStringsW(wcs.c_str(), NULL, 0);
	pwcs = static_cast<wchar* >(malloc(size * sizeof(wchar)));
	if (pwcs == NULL) return L"";
	if (ExpandEnvironmentStringsW(wcs.c_str(), pwcs, size) == 0) wcsTemp = L"";
	else wcsTemp = pwcs;
	free(pwcs);

	return wcsTemp;
}

string cz_msc_ExpandStringA(stringc& str)
{
	u32 size;
	string strTemp;
	char* pstr;

	size = ExpandEnvironmentStringsA(str.c_str(), NULL, 0);
	pstr = static_cast<char* >(malloc(size * sizeof(char)));
	if (pstr == NULL) return "";
	if (ExpandEnvironmentStringsA(str.c_str(), pstr, size) == 0) strTemp = "";
	else strTemp = pstr;
	free(pstr);

	return strTemp;
}

/* GetDoubleNullStringX-------------------------------------------------------------------------------------*/
wstring cz_msc_GetDoubleNullStringW(vector<wstring > const& vct)
{
	u32 i;
	wstring wcs = L"";
	for (i = 0; i < vct.size(); ++i) wcs.append(vct[i].c_str(), vct[i].size() + 1);
	wcs.append(L"\0", 1);
	return wcs;
}

string cz_msc_GetDoubleNullStringA(vector<string > const& vct)
{
	u32 i;
	string str = "";
	for (i = 0; i < vct.size(); ++i) str.append(vct[i].c_str(), vct[i].size() + 1);
	str.append("\0", 1);
	return str;
}